﻿@using LanDBom.Models
@using LanDBom.Resources
@{
    ViewBag.Title = "General";
    Layout = "~/Views/Shared/_Genertals.cshtml";
}
<from>
    <fieldset class="boun">
        <legend></legend>
        <div class="row bian">
            <label class="col-sm-3 breadcrumb-item ">步骤六：对外报价</label>
            <ul id="lisul" class="row col-sm-5">
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu">6</li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>
            </ul>
        </div>
    </fieldset>
</from>
<div id="wid">
    <form class="row padtop col-12">
        <fieldset class="boun">
            <legend class="len">查询条件</legend>
            <div class="row">
                <p class="col">
                    @Html.Label(Resource.String152)
                    @Html.TextBox("shen")
                </p>
                <p class="col">
                    @Html.Label(Resource.String153)
                    @Html.TextBox("ming")
                </p>
                <p class="col">
                    @Html.Label(Resource.String154)
                    @Html.TextBox("shi")
                </p>
                <p class="col">
                    @Html.Label("项目负责人")
                    <select style="width:143px;height:23px;padding:1px;" id="XMfzr">
                    </select>
                </p>
                <p class="col">
                    <input type="button" value="@Resource.String155" name="cha" class="btn-secondary btn-sm" />
                </p>
            </div>

        </fieldset>
    </form>
    <div>
        <table class="table tab">
            <thead class="thead-light">
                <tr style="text-align-last:center;">
                    <th scope="col" style="width:70px;">@Resource.String156</th>
                    <th scope="col" id="Dan">@Resource.String157</th>
                    <th scope="col" style="width:340px;">@Resource.String158</th>
                    <th scope="col">@Resource.String159</th>
                    <th scope="col">@Resource.String160</th>
                    <th scope="col">@Resource.String161</th>
                    <th scope="col" >发起人</th>
                    <th scope="col" >项目负责人</th>
                    <th scope="col" >@Resource.String162</th>
                    <th scope="col" style="width:130px;"></th>
                </tr>
            </thead>
            <tbody class="gun" id="BUtain" style="height:570px;">
                
            </tbody>
        </table>
    </div>
</div>
@section scripts{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>

        //点击申请单号判断当前步骤进行跳转
        $(function () {
            $("#li7").css({ "color": "black", "background-color": "white" })
            $(document).on("click", "#Dan", function (e) {
                var B_dan = $(e.target).text();
                var B_dount = $(e.target).next().text();
                var B_zhang = $(e.target).parent().children().eq(11).text();
                //2:bom 3:工艺 4:询价 6：报价
                $.ajax({
                    url: '/Home/Index',
                    type: 'POST',
                    data: { "AP_bian": B_dan, "states": 2 },
                    success: function (date) {
                        if (date==1) {
                            if (B_dount == 1 || B_dount == null) {
                                alert("请重新创建！");
                            } else if (B_dount == 2) {
                                window.location.href = "/Cuobaojia/Boms?names=" + B_dan;
                            } else if (B_dount == 3) {
                                window.location.href = "/Cuobaojia/Index?names=" + B_dan;
                            } else if (B_dount == 4) {
                                window.location.href = "/Cuobaojia/BomsView?names=" + B_dan;
                            }
                        } else {
                            if (B_zhang == 3) {
                                if (B_dount == 1) {
                                    alert("请重新创建！");
                                } else if (B_dount == 2) {
                                    window.location.href = "/Contracts/Design_order?DTon=" + B_dan;
                                }else if (B_dount == 3) {
                                    window.location.href = "/Contracts/Inspect_Contracts";
                                }
                            } else {
                                if (B_dount == 1) {
                                    alert("请重新创建！");
                                } else if (B_dount == 2) {
                                    window.location.href = "/Detailed/Boms?names=" + B_dan;
                                } else if (B_dount == 3) {
                                    window.location.href = "/Material/Index?names=" + B_dan;
                                } else if (B_dount == 4 || B_dount == 5) {
                                    window.location.href = "/Procure/Overview";
                                } else if (B_dount == 6) {
                                    window.location.href = "/Custom/Profit?names=" + B_dan;
                                }
                            }
                        }
                    },
                    error: function () {
                        alert("错误 请重试！")
                    }
                })
            })
        })
        //查询功能
        $(function () {
            $('input[name="cha"]').click(function () {
                skonf()
            })
            skonf()
            sknffook()
            FUzher()
            function FUzher() {
                $.ajax({
                    url: '/Application/Application',
                    type: 'POST',
                    data: { "state": 30 },
                    success: function (path) {
                        if (path == "获取错误") {
                            alert(path)
                        } else {
                            $("#XMfzr option").remove()
                            $("#XMfzr").append(`<option value=""></optino>`)
                            $.each(path, function (i, item) {
                                var $op = $(`<option value="${item[0]}">${item[0]}</optino>`)
                                $("#XMfzr").append($op)
                            })
                        }
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            }
            function sknffook() {
                var len = $('#BUtain tr').length;
                for (var i = 0; i < len; i++) {
                    //获取当前行的值
                    var shuan = $('#BUtain tr:eq(' + i + ') td:nth-child(4)').text() * 1;
                    var zhang = $('#BUtain tr:eq(' + i + ') td:nth-child(14)').text() * 1;
                    $('#BUtain tr:eq(' + i + ') td:nth-last-child(3) div div').remove();
                    for (var j = 1; j <= zhang; j++) {
                        var $li = $(`<span style="height:13px;width:13px;border:1px solid deepskyblue;margin: 4px;"></span>`);
                        if (j <= shuan) {
                            var $li = $(`<span style="height:13px;width:13px;background-color:deepskyblue;margin: 4px;"></span>   `);
                        }
                        $('#BUtain tr:eq(' + i + ') td:nth-last-child(3) div').append($li);
                    }
                    $('#BUtain tr:eq(' + i + ') td:first').text(i + 1);
                }
            }
            function skonf() {
                var shen = $("#shen").val()
                var shi = $("#shi").val()
                var ming = $("#ming").val()
                var XMfzr = $("#XMfzr").val()
                $.ajax({
                    url: '/Custom/General',
                    type: 'POST',
                    data: { "AP_bian": shen, "App_Kehu": ming, "App_JTime": shi, "states": 1, "XMfzr": XMfzr,"SHun":6 },
                    success: function (date) {
                        console.log(date)
                        createRow(date);
                    },
                    error: function () {
                        alert("错误 请重试！")
                    }
                })
            }
            function createRow(date) {
                $("#BUtain tr").remove();
                $.each(date, function (i, item) {
                    var $tr = (`<tr>
                    <td style="width:70px;"></td>
                                <td style="display:none">${item.App_id}</td>
                                <td id="Dan" style="color:#2a6bcc;">${item.AP_bian}</td>
                                <td class="sr-only C_jin" style="display:none" id="poi">${item.App_bu}</td>
                                <td style="width:370px;">${item.App_Kehu}</td>
                                <td>${item.APP_name}</td>
                                <td>${item.App_qishi}</td>
                                <td>${item.App_JTime}</td>
                                <td>${item.AP_ren}</td>
                                <td>${item.App_fzr}</td>
                                <td style="display:none" id="shun">${item.APP_fenL}</td>
                                <td style="width:150px">
                            <div style="display:flex">
                            </div>
                        </td>
                                 <td style="width:70px;"></td>
                                 <td style="display:none" id="zhand">${item.App_zhand}</td>
                            </tr>
                    `);

                    if ($("#Login_sf").text() == "客户经理" || $("#Login_sf").text() == "销售助理") {
                        $("#BUtain").append($tr);
                    }
                    else if ($("#Login_sf").text() == "销售") {
                        if (item.AP_ren == $("#Login_N").text() || item.App_fzr == $("#Login_N").text()) {
                            $("#BUtain").append($tr);
                        }
                    }
                })
                sknffook()
            }
        })
    </script>
}